home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.multimedia;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import symantec.itools.lang.OS;
-
- public class Firework extends Canvas implements Runnable {
- public int AnimationSpeed = 10;
- public int RocketStyleVariability = 10;
- public int MaxRocketNumber = 9;
- public int MaxRocketExplosionEnergy = 850;
- public int MaxRocketPatchNumber = 90;
- public int MaxRocketPatchLength = 68;
- public int Gravity = 400;
- private Rocket[] rocket;
- private boolean rocketsCreated = false;
- private Thread launcher;
- private boolean suspend = false;
-
- public void addNotify() {
- super.addNotify();
- this.launcher = new Thread(this);
- this.launcher.start();
- }
-
- public synchronized void removeNotify() {
- if (this.launcher != null) {
- this.launcher.stop();
- this.launcher = null;
- }
-
- super.removeNotify();
- }
-
- public synchronized void show() {
- super.show();
- if (((Component)this).isVisible() && this.launcher != null) {
- this.launcher.resume();
- }
-
- }
-
- public synchronized void hide() {
- super.hide();
- if (!((Component)this).isVisible() && this.launcher != null) {
- this.suspend = true;
- }
-
- }
-
- void createRockets() {
- this.rocketsCreated = true;
- Rocket[] var1 = new Rocket[this.MaxRocketNumber];
- Dimension var2 = ((Component)this).size();
-
- for(int var3 = 0; var3 < this.MaxRocketNumber; ++var3) {
- var1[var3] = new Rocket(var2.width, var2.height, this.Gravity);
- }
-
- this.rocket = var1;
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.rocketsCreated = false;
- }
-
- public void run() {
- int var2 = (int)(Math.random() * (double)this.MaxRocketExplosionEnergy * (double)3.0F / (double)4.0F) + this.MaxRocketExplosionEnergy / 4 + 1;
- int var3 = (int)(Math.random() * (double)this.MaxRocketPatchNumber * (double)3.0F / (double)4.0F) + this.MaxRocketPatchNumber / 4 + 1;
- int var4 = (int)(Math.random() * (double)this.MaxRocketPatchLength * (double)3.0F / (double)4.0F) + this.MaxRocketPatchLength / 4 + 1;
- long var5 = (long)(Math.random() * (double)10000.0F);
- Graphics var8 = null;
-
- while(true) {
- if (var8 == null) {
- var8 = ((Component)this).getGraphics();
- }
-
- if (this.suspend) {
- this.suspend = false;
- this.launcher.suspend();
- }
-
- if (!this.rocketsCreated) {
- this.createRockets();
- }
-
- if (this.rocketsCreated && var8 != null) {
- Dimension var9 = ((Component)this).size();
- if (OS.isMacintosh()) {
- var8.clipRect(0, 0, var9.width, var9.height);
- }
-
- try {
- Thread.sleep((long)(100 / this.AnimationSpeed));
- } catch (InterruptedException var11) {
- }
-
- boolean var7 = true;
-
- for(int var1 = 0; var1 < this.MaxRocketNumber; ++var1) {
- var7 = var7 && this.rocket[var1].sleep;
- }
-
- if (var7 && Math.random() * (double)100.0F < (double)this.RocketStyleVariability) {
- var2 = (int)(Math.random() * (double)this.MaxRocketExplosionEnergy * (double)3.0F / (double)4.0F) + this.MaxRocketExplosionEnergy / 4 + 1;
- var3 = (int)(Math.random() * (double)this.MaxRocketPatchNumber * (double)3.0F / (double)4.0F) + this.MaxRocketPatchNumber / 4 + 1;
- var4 = (int)(Math.random() * (double)this.MaxRocketPatchLength * (double)3.0F / (double)4.0F) + this.MaxRocketPatchLength / 4 + 1;
- var5 = (long)(Math.random() * (double)10000.0F);
- }
-
- for(int var12 = 0; var12 < this.MaxRocketNumber; ++var12) {
- Rocket var10 = this.rocket[var12];
- if (var10.sleep && Math.random() * (double)this.MaxRocketNumber * (double)var4 < (double)1.0F) {
- var10.init(var2, var3, var4, var5);
- var10.start();
- }
-
- if (this.rocketsCreated) {
- var10.show(var8);
- }
- }
- }
- }
- }
-
- public void freezeRockets() {
- this.suspend = true;
- }
-
- public void unfreezeRockets() {
- this.launcher.resume();
- }
-
- public void paint(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- var1.clipRect(0, 0, var2.width, var2.height);
- var1.setColor(Color.black);
- var1.fillRect(0, 0, var2.width + 1, var2.height + 1);
- }
- }
-